package com.tsj.SpringBoot.ThreadManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RunnableDemo implements Runnable{
	private final static Logger logger = LoggerFactory.getLogger(RunnableDemo.class);
	private Thread t;
	private String threadName;
	public RunnableDemo(String name) {
		this.threadName = name;
		logger.info("creatThread :"+threadName);
	}
	@Override
	public void run() {
		logger.info("runing :"+threadName);
		 try {
	         for(int i = 4; i > 0; i--) {
	        	 logger.info("Thread: " + threadName + ", " + i);
	            // 让线程睡眠一会
	            Thread.sleep(50);
	         }
	      }catch (InterruptedException e) {
	    	  logger.info("Thread " +  threadName + " interrupted.");
	      }
		 logger.info("Thread " +  threadName + " exiting.");
	}
	
	public void start() {
		logger.info("Starting  :"+threadName);
		if(t == null) {
			t = new Thread (this, threadName);
	         t.start ();
	         notifyAll();
		}
		
	}
		
		

}
